package com.boco.webmaster.model;

import java.util.*;

import com.boco.transnms.client.model.base.*;
import com.boco.transnms.common.dto.*;
import com.boco.transnms.common.dto.base.*;
import com.boco.transnms.server.bo.base.BoHomeFactory;
import com.boco.transnms.server.bo.base.BoName;
import com.boco.transnms.server.bo.helper.cm.*;
import com.boco.transnms.server.bo.ibo.cm.INmsSystemBOX;
import com.boco.transnms.server.bo.ibo.cm.ISpBOX;

public class VenderModel {
    private static VenderModel instance = new VenderModel();
    private Map venderMap = new HashMap();
    public VenderModel() {
        refresh();
    }

    public void refresh() {
    	INmsSystemBOX ibo = (INmsSystemBOX)BoHomeFactory.getInstance().getBO(BoName.NmsSystemBOX);
        DataObjectList dbos = ibo.getAllDeviceVendor(new BoActionContext());
        for (int i = 0; i < dbos.size(); i++) {
            DeviceVendor dbo = (DeviceVendor) dbos.get(i);
            venderMap.put(dbo.getCuid(), dbo);
        }
    }

    public static VenderModel getInstance() {
        return instance;
    }

    public void addDeviceVendor(DeviceVendor deviceVendor){
        venderMap.put(deviceVendor.getCuid(),deviceVendor);
    }

    public void delDeviceVendor(String  cuid){
        venderMap.remove(cuid);
    }

    public void modifyDeviceVendor(DeviceVendor deviceVendor){
        venderMap.put(deviceVendor.getCuid(),deviceVendor);
    }

    public void delDeviceVendorByObjectId(Long objectid){
        Iterator iterator = venderMap.keySet().iterator();
        while (iterator.hasNext()) {
            String vendor_cuid = (String)iterator.next();
            DeviceVendor dbo = (DeviceVendor) venderMap.get(vendor_cuid);
            if(dbo.getObjectNum()==objectid){
                iterator.remove();
            }
        }
    }

    public String getValue(String cuid) {
        DeviceVendor dbo = ((DeviceVendor)venderMap.get(cuid));
        if(dbo!=null && dbo.getLabelCn()!=null){
            return dbo.getLabelCn();
        }else{
            return "";
        }
    }

    public String getLabelCnByCuid(String cuid) {
        DeviceVendor dbo = ((DeviceVendor)venderMap.get(cuid));
        if(dbo!=null && dbo.getLabelCn()!=null){
            return dbo.getLabelCn();
        }else{
            return "";
        }
    }

    public DeviceVendor getDeviceVendorCuid(String cuid) {
        return (DeviceVendor)venderMap.get(cuid);
    }

    public String getCuidByLabelCn(String label_cn){
           Iterator i = venderMap.keySet().iterator();
           while (i.hasNext()) {
               String vender_cuid = (String) i.next();
               DeviceVendor dbo = (DeviceVendor) venderMap.get(vender_cuid);
               if(dbo.getLabelCn().equals(label_cn)){
                   return dbo.getCuid();
               }
           }
           return null;
    }
    public Object[] getKeys() {
        return venderMap.keySet().toArray();
    }

    public DataObjectList getAllVendor() {
        DataObjectList dbos = new DataObjectList();
        Iterator i = venderMap.keySet().iterator();
        while (i.hasNext()) {
            String vendor_cuid = (String) i.next();
            DeviceVendor dbo = (DeviceVendor) venderMap.get(vendor_cuid);
            dbos.add(dbo);
        }
        return dbos;
    }

}
